home *** CD-ROM | disk | FTP | other *** search
- #include <Dialogs.h>
- #include <Controls.h>
- #include <QuickDraw.h>
- #include <Windows.h>
- #include <ToolUtils.h>
- #include <OSUtils.h>
- #include <Menus.h>
- #include <Fonts.h>
- #include <resources.h>
- #include <Sound.h>
- #include <Traps.h>
- #include <Gestaltequ.h>
- #include <Memory.h>
- #include <Scrap.h>
- #include <TextEdit.h>
-
- /* These are the new Dialog Manager calls described in Tech note #304 */
- /* ONLY used if System 7 or later, of course */
- pascal OSErr GetStdFilterProc(ModalFilterProcPtr *theProc) =
- {
- 0x303C, 0x0203, 0xAA68
- };
-
-
-
-
- /* Indicates to the dialog manager which item is default. Will then alias the return key */
- /* to this item, and also bold border it for you (yaaaaa!) */
- pascal OSErr SetDialogDefaultItem(DialogPtr theDialog, short newItem)
- =
- {
- 0x303C, 0x0304, 0xAA68
- };
-
-
-
-
- /* Indicates which item should be aliased to escape or Command - . */
- pascal OSErr SetDialogCancelItem(DialogPtr theDialog, short newItem)
- =
- {
- 0x303C, 0x0305, 0xAA68
- };
-
-
-
-
- /* Tells the dialog manager that there is an edit line in this dialog, and */
- /* it should track and change to an I-Beam cursor when over the edit line */
- pascal OSErr SetDialogTracksCursor(DialogPtr theDialog, Boolean tracks) =
- {
- 0x303C, 0x0306, 0xAA68
- };
-
-
-
- ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem);
- pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem);
- void ToggleCheckBox(DialogPtr myDialog,short theItem);
-
-
-
-
-
-
-
-
-
- enum {
- /* ok and cancel are already defined in Dialogs.h */
- kMessUpItem = 3,
- kHiliteOK
- };
- enum {
-
- kSampleDialog = 128,
- kMessUpAlert
- };
-
-
- main()
- {
- DialogPtr myDialog = nil; /* the dialog wee're using */
- short hitItem = 0; /* hitItem for ModalDialog */
- Rect tempRect; /* these three are here for all the GetDItem/SetDItem calls*/
- short tempItem;
- Handle tempHandle;
- Boolean tempBool; /* a temporary boolean (now THAT'S a helpful comment */
- /* start up manahers */
- InitGraf((Ptr)&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- /* get our dialog */
- myDialog = GetNewDialog(kSampleDialog, nil, (WindowPtr)-1);
-
-
-
- SetDialogDefaultItem(myDialog, ok);
- SetDialogCancelItem(myDialog, cancel);
- /* dim the OK button initially */
- HiliteControl(SnatchHandle(myDialog,ok),255);
-
- do {
- ModalDialog((ModalFilterProcPtr)filterIt, &hitItem);
- if(hitItem == kMessUpItem){
- /* bring up an alert to obscure the OK button */
- Alert(kMessUpAlert,nil);
- }
- else{
- if(hitItem == kHiliteOK)
- ToggleCheckBox(myDialog,kHiliteOK);
- HiliteControl(SnatchHandle(myDialog,ok),GetCtlValue(SnatchHandle(myDialog,hitItem)) ? 0 : 255);
-
- }
-
- }
- while (hitItem != ok && hitItem != cancel);
- DisposDialog(myDialog);
- InitCursor(); /* Init to prevent I-beam from hanging around in some circumstances */
-
-
-
-
-
-
- }
-
-
- pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem)
- {
- ModalFilterProcPtr theModalProc; /* address of standard filter */
-
-
- if (/* myDialogEvent->what == activateEvt || */myDialogEvent->what == updateEvt) {
- /* reset the state of the button based on my */
- /* check box. Use whatever conditions you need to determine the */
- /* correct highlighting */
- HiliteControl(SnatchHandle(inputDialog,ok),GetCtlValue(SnatchHandle(inputDialog,kHiliteOK)) ? 0 : 255);
-
- }
- /* You must still call through the standard filter for things to work, of course */
- GetStdFilterProc( &theModalProc ) ;
- return ( theModalProc( inputDialog, myDialogEvent, theDialogItem ) );
-
- }
-
- ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem)
- {
- short itemtype;
- Rect itemrect;
- Handle thandle;
-
- GetDItem(thebox, theGetItem, &itemtype, &thandle, &itemrect);
- return((ControlHandle)thandle);
- } /* end SnatchHandle */
-
-
- void ToggleCheckBox(DialogPtr myDialog,short theItem)
- {
-
- SetCtlValue(SnatchHandle(myDialog,theItem),GetCtlValue(SnatchHandle(myDialog,theItem)) ? false:true);
- }
-
-